//
//  EvaluateItemView.m
//  FD
//
//  Created by xiaofang wang on 2018/11/12.
//  Copyright © 2018年 ZhiYuan Network. All rights reserved.
//

#import "EvaluateItemView.h"

@implementation EvaluateItemView
- (instancetype)initWithFrame:(CGRect)frame title:(NSString *)title {
    self = [super initWithFrame:frame];
    if (self) {
        [self setupView:title];
    }
    return self;
}

- (void)setupView:(NSString *)title {
    [self addSubview:self.nameLb];
    self.nameLb.text = title;
    [self addSubview:self.starView];
    
    //    self.nameLb = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];
    //    self.nameLb.text = title;
    //    [self addSubview:self.nameLb];
    //
    //    CGFloat x = (self.frame.size.width - 120 - 10);
    //    CGRect starFrame = CGRectMake(x, 10, 120, 30);
    //    self.starView = [[XHStarRateView alloc] initWithFrame:starFrame completion:^(CGFloat currentScore) {
    //        NSLog(@"点击了 %f 星",currentScore);
    //
    //        if (self.currentScoreBlock) {
    //            self.currentScoreBlock(currentScore);
    //        };
    //    }];
    //    self.starView.currentRating = 5; //默认全亮
    //    [self addSubview:self.starView];
}


//layout
- (void)layoutSubviews {
    [super layoutSubviews];
    [self.nameLb mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(10);
        make.size.mas_equalTo(CGSizeMake(100, 30));
        make.centerY.equalTo(self.mas_centerY);
    }];
    [self.starView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_equalTo(CGSizeMake(100, 20));
        make.centerY.equalTo(self.mas_centerY);
        make.right.equalTo(self.mas_right).offset(-10);
    }];
}

#pragma mark - getter
- (UILabel *)nameLb {
    if (!_nameLb) {
        _nameLb = [[UILabel alloc] init];
        _nameLb.textColor = kLightGrayTextColor; //深灰色
        _nameLb.font = [UIFont systemFontOfSize:15.0];
    }
    return _nameLb;
}
- (XHStarRateView *)starView {
    if (!_starView) {
        _starView = [[XHStarRateView alloc] initWithFrame:CGRectMake(0, 0, 100, 20) completion:^(CGFloat currentScore) {
//            FDLog(@"点击了 %f 星",currentScore);
            if (self.currentScoreBlock) {
                self.currentScoreBlock(currentScore);
            };
        }];
        
        //全星
        _starView.rateStyle = XHStarRateViewRateStyeFullStar;
        _starView.currentRating = 5; //默认全亮
    }
    return _starView;
}

@end
